//
//  HomeModelViewModel.swift
//  微博01
//
//  Created by 牛威 on 15/12/11.
//  Copyright © 2015年 牛威. All rights reserved.
//

import Foundation


class HomeModelViewModel {
    
    
    //懒加载数据数组
    
    lazy var arrayM = [HMViewModel]()
    
    
    
    func loadHomeModelData(finished:(isSuccessed:Bool)->()){
        
        NetTools.shared.loadStatus { (result, error) -> () in
            
            if error != nil {
                
                print("error")
                
                finished(isSuccessed: false)
                return
                
            }
            
            //遍历数组字典 [[String : AnyObject]]--->装着字典的数组格式
            
            guard let array = result?["statuses"] as? [[String : AnyObject]] else {
                
                
                print("数组格式有误")
                
                finished(isSuccessed: false)
                return
                
            }
            
            
            // 创建一个可变的数组
            
            var arrayM = [HMViewModel]()
            
            
            
            //  遍历数组字典 并字典转模型
            
            for dict in array {

                arrayM.append(HMViewModel(homeModel: NWHomeModel(dict: dict)))

            }
            
            //拼接数组
            
            self.arrayM = arrayM + self.arrayM
            
            print(self.arrayM) //这里想要打印数据 就得遵守一个协议兵重写 description方法-->HMViewmodel文件中去
            
            
            //成功回调
            
            finished(isSuccessed: true)
            
        }
        
        
        
    }
    
    
}
